fn main() {
    let papernews = PaperNews{
        info:String::from("AAA"),
    };

    let tvnews = TVNews{
        info:String::from("BBB"),
    };

    println!("{}",papernews.trump());
    println!("{}",tvnews.trump());

    print_news_say(papernews);
    print_news(tvnews);

    let p = get_news();

    print_news(p);

    let list = vec![1,2,3,4,5];

    println!("{}",largers(&list));

    println!("{}",largers_without_copy(&list));

    println!("Hello, world!");
}

// fn largers<T>(list : &[T]) -> T {
//     let mut larger : T = list[0];

//     for &item in list.iter() {
//         if item > larger {
//             larger = item;
//         }
//     }

//     larger;
// }

fn largers<T : PartialOrd + Copy>(list : &[T]) -> T {
    let mut larger : T = list[0];

    for &item in list.iter() {
        if item > larger {
            larger = item;
        }
    }

    larger
}

fn largers_without_copy<T : PartialOrd>(list : &[T]) -> &T {
    let mut larger : &T = &list[0];

    for item in list.iter() {
        if item > larger {
            larger = item;
        }
    }

    larger
}

trait News{
    fn trump(&self) -> String {
        String::from("Faker news!")
    }
}

struct PaperNews{
    info :String,
}

struct TVNews{
    info :String,
}

impl News for PaperNews{
    fn trump(&self) -> String {
        format!("{} :{} {}",String::from("PaperNews"),self.info,String::from("is faker news!"))
    }
}

impl News for TVNews{}

fn print_news_say(new : impl News){
    println!("{}" , new.trump());
}

fn print_news<T :News>(new :T){
    println!("{}",new.trump());
}

fn get_news() -> impl News {
    PaperNews{
        info: String::from("111111"),
    }
}